<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>zabbix监控mongodb | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>zabbix监控mongodb</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Zabbix/">Zabbix</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mongodb的监控，下面是部署过程：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;第一步，先在zabbix_agentd.conf中追加下面的内容，主要是调用mongo这个工具通过db.serverStatus()函数获取mongodb的状态，这里需要注意的是连接的IP和端口不能配置错误，最好是要检查一下mongodb的配置文件里面的IP和端口是否一致：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#monitor mongodb</span></div><div class="line">UserParameter=mongo.service,ps -ef | grep mongo |grep -v grep |wc -l</div><div class="line">UserParameter=mongo.mem_resident,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep resident | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.mem_virtual,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep virtual | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.mem_mapped,<span class="built_in">echo</span> <span class="string">"db.serverStatus().mem"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep <span class="string">'\bmapped\b'</span> | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f 1| cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.network[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().network"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span> | cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.index[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().indexCounters"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span>| cut -d <span class="string">":"</span> -f 2 |cut -d <span class="string">","</span> -f1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.connection_current,<span class="built_in">echo</span> <span class="string">"db.serverStatus().connections"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current|cut -d <span class="string">":"</span> -f 2|cut -d <span class="string">","</span> -f 1|cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.connection_available,<span class="built_in">echo</span> <span class="string">"db.serverStatus().connections"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current| cut -d <span class="string">":"</span> -f 3|cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.opcounters[*],<span class="built_in">echo</span> <span class="string">"db.serverStatus().opcounters"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep <span class="variable">$1</span>|cut -d <span class="string">":"</span> -f 2|cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.rpstatus,<span class="built_in">echo</span> <span class="string">"rs.status()"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep myState| cut -d <span class="string">":"</span> -f 2| cut -d <span class="string">","</span> -f 1 |cut -d <span class="string">" "</span> -f 2</div><div class="line">UserParameter=mongo.queue_write,<span class="built_in">echo</span> <span class="string">"db.serverStatus().globalLock.currentQueue.writers"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.queue_reader,<span class="built_in">echo</span> <span class="string">"db.serverStatus().globalLock.currentQueue.readers"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.backgroundFlush,<span class="built_in">echo</span> <span class="string">"db.serverStatus().backgroundFlushing.last_ms"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.curosor_Totalopen,<span class="built_in">echo</span> <span class="string">"db.serverStatus().cursors.totalOpen"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.curospr_timedOu,<span class="built_in">echo</span> <span class="string">"db.serverStatus().cursors.timedOut"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.pagefaults,<span class="built_in">echo</span> <span class="string">"db.serverStatus().extra_info.page_faults"</span> |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p</div><div class="line">UserParameter=mongo.oplog_storetime,<span class="built_in">echo</span> <span class="string">"db.printReplicationInfo()"</span>|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 4p|cut -d <span class="string">"("</span> -f 2|cut -d <span class="string">"h"</span> -f 1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;追加完成后重启zabbix_agentd然后在zabbix_server端使用zabbix_get尝试是否能够获取到数据，如果能获取到数据说明客户端已经配置好了，接下来配置服务端，将下面提供的模板导入，然后添加相应主机到模版中就行了。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Zabbix/13. zabbix监控mongodb/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
